﻿<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\web\View;
use backend\models\service\AdminService as Admin;
use backend\models\service\Chapter;
use yii\helpers\Url;
?>

<div class="pushactivity-form">
    <article class="center">
        <?php
        $form = ActiveForm::begin([
            'id' => $model->formName(),
            'enableAjaxValidation' => true,
            'fieldConfig' => [
                    'template' => '<div style="height:50px;"><div class="col-xs-3">{label}</div><div class="col-xs-5">{input}{error}</div></div>',
                ]
        ]);
        ?>
        <input type="hidden" id="novel" value="<?php echo isset($id) ? $id : '';?>">
        <?php $model->charge_model = 0 ?>
        <?= $form->field($model, 'charge_model')->textInput()->radioList(['0' => '免费', '1' => '按章节', '2' => '按完本'])->label('收费模式') ?>
        <?=$form->field($model, 'charge_start_chapter',['template'=>'<div style="height:50px;"><div class="col-xs-3">{label}</div><div class="col-xs-5">{input}{error}</div><div class="col-xs-1" style="margin-top:5px;margin-left: -20px;">章</div></div>'])->textInput(['maxlength' => 10])->label('收费启动章节')?>
        <?=$form->field($model, 'charge_price',['template'=>'<div style="height:50px;"><div class="col-xs-3">{label}</div><div class="col-xs-5">{input}{error}</div><div class="col-xs-3" id = "charge-model" style="margin-top:5px;margin-left: -20px;">阅币/章</div></div>'])->textInput(['maxlength' => 20])->label('收费标准')?>
        <?= Html::submitButton('保存创建', ['class' => 'btn btn-primary sub', 'name' => 'submit-button']) ?>
        <?php ActiveForm::end(); ?>

    </article>
</div>

<script>
 $(function(){
    $(".field-charge-charge_start_chapter").hide();
    $(".field-charge-charge_price").hide();
    $(":radio").click(function(){
        var id =  $(this).val();
        if(id == 0){
            $(".field-charge-charge_start_chapter").hide();
            $(".field-charge-charge_price").hide();
        }else if(id == 1){
            $(".field-charge-charge_start_chapter").show();
            $(".field-charge-charge_price").show();
            $("#charge-model").html('阅币/章');
        }else if(id == 2){
            $(".field-charge-charge_start_chapter").hide();
            $(".field-charge-charge_price").show();
            $("#charge-model").html('阅币/本');
        }
    });
    
    $(".sub").click(function(){
        if(zz_keys == ''){
            alert('请选择需要操作的小说');
            return false;
        }
        var model = $('input:radio:checked').val();
        var chapter = $("#charge-charge_start_chapter").val();
        var price = $("#charge-charge_price").val();
        var csrf = $("input[name=_csrf-backend]").val();
        var ids = zz_keys;
        var novel = $("#novel").val();
    //    var datas = {model:model,chapter:chapter,price:price,ids:ids,_csrf-backend:csrf};
        $.ajax({
            url: "/novel/charge-setting-batch",
            type: "POST",
            dataType: "json",
            data: {'model':model,'chapter':chapter,'price':price,'ids':ids,'novel':novel,'_csrf-backend':csrf},
            success: function(Data) {
                if(Data.status == 0){
                    alert('保存成功');
                }else{
                    alert('保存失败');
                }
                location.href="/novel/index"
                zz_keys = ''
            },
            error: function() {
                alert('网络错误！');
                location.href="/novel/index"
                zz_keys = ''
            }
        });
        return false;
     });
 });
 
</script>